<?php
namespace Home\Controller;

use Think\Controller;
class IndexController extends BaseController {
	
    /**
     * 测试函数
     * @return [type] [description]
     */
    public function test(){
        var_dump(123);
    }

    //通过查找用户订单信息，统计出用户各个服务使用信息
    public function find_use_info(Type $var = null)
    {
        # code...
        // 实例化用户订单数据表
        $Message = M('bill');

        //设置订单查询条件：根据用户ID查找订单
        $where = array();
        $where['uid'] = 1;

        //按照时间倒序查询数据
        $all_message = $Message->where($where)->select();

        // dump($all_message);

        // dump($Message->getLastSql());

        $return_data = array();
        $return_data['error_code'] = 0;
        $return_data['msg'] = '数据获取成功';
        $return_data['data'] = $all_message;

        $this->ajaxReturn($return_data);

    }

    //修改用户优惠卷数量接口
    public function modify_coupons_num(Type $var = null)
    {
        # code...
        // 实例化数据表
        $Message = M('userpaid');

        //设置where修改条件
        $where = array();
        $where['uid'] = 2;

        //要保存的数据
        $data = array();
        $data['ndrink'] = 1;

        //保存修改数据
        $result = $Message->where($where)->save($data);

        dump($result);


    }

    //测试删除接口
    public function delete_test(Type $var = null)
    {
        # code...
        // 实例化数据表
        $Message = M('userpaid');

        //设置where删除条件
        $where = array();
        $where['uid'] = 2;

        //删除数据
        $result = $Message->where($where)->delete();

        dump($result);


    }

    //find_bill账单接口
    public function find_bill(Type $var = null)
    {
        # code...
        // 实例化账单数据表
        $Bill = M('bill');

        //设置where条件查询用户id在表bill中所有信息
        $where = array();
        $where['uid'] = 1;


        //查询数据
        $all_message = $Bill->where($where)->select();

        dump($all_message[0]['did']);
        

        $i = 0;
        while ($all_message[i]) {
            # code...
            $device = M('device');
             //设置where条件查询设备id在表device中所有信息
            $where = array();
            $where['did'] = $all_message[i]['did'];
            
            
            $device_message = $device->where($where)->find();
            $i++;
            dump($device_message);
        }
       
        dump($all_message);


    }
   

}
